<?php
/**
 * FCommentoUtente.php
 * @author Igor Di Paolo
 * @package Foundation
 */
/**
 * FCommentoUtente
 * @author mw
 * @package Foundation
 *
 */
class FCommentoUtente extends Fdatabase {
	/**
	 * Costruttore
	 */
	public function __construct() {
		parent::__construct('ECommentoUtente','bacheca',array('owner','writer','timestamp'));
	}
	/**
	 * Query per costruire la bacheca
	 * @param string utente
	 * @param integer num_commenti
	 * @param integer start_commenti
	 */
	public function getBachecaUtente($utente,$num_commenti = 10,$start_commenti = -1) {
		
		$start;
		$end;
		
		if($start_commenti != -1){
			$start = $start_commenti;
			$end = $start_commenti + $num_commenti;
		}else {
			$start = 0;
			$end = $num_commenti;
		}
		
		$query .= 'SELECT * FROM bacheca LEFT OUTER JOIN utente ON utente.username = bacheca.writer 
			WHERE bacheca.owner = '.$this->safeString($utente).'ORDER BY timestamp DESC
			LIMIT '.$this->safeString($start).','.$this->safeString($end).';';
			
		$this->_query($query);
	}
	
}